<?php

class PriceCalculator
{
  
  /**
   * @var PriceScaling
   */
  private $scaling;
  
  /**
   * @var Doctrine_Collection
   */
  private $bookings;
  
  /**
   * @var Doctrine_Collection
   */
  private $payments;
  
  /**
   * @var Doctrine_Collection
   */
  private $participants;
  
  /**
   * @var Doctrine_Collection
   */
  private $tents;
  
  /**
   * @var boolean
   */
  private $calculated = false;
  
  /**
   * @var double
   */
  private $amount_payed;
  
  /**
   * @var double
   */
  private $amount_due;

  public function __construct (Doctrine_Collection $bookings, Doctrine_Collection $payments, 
      Doctrine_Collection $participants = null)
  {
//    $this->scaling = $scaling;
    $this->bookings = $bookings;
    $this->payments = $payments;
    $this->participants = $participants;
//    $this->tents = $tents;
  }

  public function getAmountPayed ()
  {
    if (! $this->calculated)
    {
      $this->calculate();
    }
  
    return $this->amount_payed;
  }

  public function getAmountDue ()
  {
    if (! $this->calculated)
    {
      $this->calculate();
    }
  
   return $this->amount_due;
  

  }

  public function calculate ()
  {
  
    $overall_amount = 0;
    foreach($this->participants as $participant) {
      //TODO $amount = $this->scaling->getAmountFor($tent);
      $overall_amount += $participant->getAmount();
    }
    
    $overall_payed = 0;
    foreach($this->payments as $payment) {
      $overall_payed += $participant->getAmount();
    }
    
    $this->amount_payed = $overall_payed;
    $this->amount_due = $overall_amount - $this->amount_payed;
    
    $this->calculated = true;
  }
}